package com.supor.aiot.food.adapter;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.android.baseconfig.common.views.RoundImageView;
import com.bumptech.glide.Glide;
import com.supor.aiot.common.app.AppAgent;
import com.supor.aiot.common.arouter.PathUrl;
import com.supor.aiot.food.R;
import com.supor.aiot.food.bean.ChefDetailBean;
import com.supor.aiot.food.utils.DoubleClickUtils;

import java.util.List;


public class RecipeChefAdapter extends RecyclerView.Adapter<RecipeChefAdapter.TopicHolder>{
    private List<ChefDetailBean> mList;
    private Context mContext;
    private static final String TOPIC_BEAN = "CHEF_BEAN";

    public RecipeChefAdapter(List<ChefDetailBean> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public RecipeChefAdapter.TopicHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_chef_class,parent, false);
        return new RecipeChefAdapter.TopicHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecipeChefAdapter.TopicHolder holder, int position) {
        ChefDetailBean chefDetailBean = mList.get(position);
        holder.rlTopicOuter.setOnClickListener(view -> {
            if (DoubleClickUtils.isFastDoubleClick())return;
            ARouter.getInstance()
                    .build(PathUrl.PATH_COOKER_HOME)
                    .withString("CHEF_ID", chefDetailBean.getChefId())
                    .withTransition(com.android.baseconfig.R.anim.activity_open_enter,
                            com.android.baseconfig.R.anim.activity_open_exit)
                    .navigation(AppAgent.getCurrentActivity());

        });
        holder.tvTopicName.setText(chefDetailBean.getChefTitle());
        Glide.with(mContext).load(chefDetailBean.getDetailImage()).placeholder(new ColorDrawable(mContext.getResources().getColor(R.color.white_f5f5f5))).into(holder.rivTopic);
        if (chefDetailBean.getIsHaveNow()==1){holder.tvNewlyTag.setVisibility(View.VISIBLE);}else{holder.tvNewlyTag.setVisibility(View.GONE);}
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class TopicHolder extends RecyclerView.ViewHolder{
        private TextView tvTopicName;
        private RoundImageView rivTopic;
        private RelativeLayout rlTopicOuter;
        private TextView tvNewlyTag;

        public TopicHolder(@NonNull View itemView) {
            super(itemView);
            tvTopicName =itemView.findViewById(R.id.tv_topic_name);
            rivTopic=itemView.findViewById(R.id.iv_recipe_class);
            rlTopicOuter=itemView.findViewById(R.id.rl_topic_outer);
            tvNewlyTag=itemView.findViewById(R.id.tv_newly_tag);
        }
    }

}
